package com.serviceprovider.business.module.order.valueobjects;

//~--- non-JDK imports --------------------------------------------------------

import com.serviceprovider.business.module.order.model.Order;
import com.serviceprovider.business.module.report.valueobjects.BatchVO;
import com.serviceprovider.business.module.sp.transaction.valueobjects.TransactionDetailsVO;
import com.serviceprovider.business.module.user.model.impl.User;

//~--- JDK imports ------------------------------------------------------------

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author mrduongnv@gmail.com
 */
public class OrderVO {
    private OrderStatusVO orderStatus = new OrderStatusVO();
    private List<String>  commentList = new ArrayList<String>();
    private List<BatchVO> batchList   = new ArrayList<BatchVO>();
    private Date          createdDate;
    private String        date;
    private Integer       id;
    private String        instructions;
    private Integer       mode;
    private String        name;
    private User          orderAssignedTo;
    private User          provider;
    private int           spId;
    private String        tips;

    public OrderVO() {}

    public OrderVO(Order order) {
        this.id              = order.getId();
        this.date            = order.getDate();
        this.name            = order.getName();
        this.mode            = order.getMode();
        this.orderStatus     = new OrderStatusVO(order.getOrderStatus());
        this.instructions    = order.getInstructions();
        this.tips            = order.getTips();
        this.orderAssignedTo = order.getOrderAssignedTo();
        this.spId            = order.getServiceProviderId();
        this.createdDate     = order.getCreatedDate();
    }

    public Integer getTotalPayeeAmount() {
        Integer totalAmount = 0;

        try {
            for (BatchVO batch : batchList) {
                for (TransactionDetailsVO transaction : batch.getTransactions().values()) {
                    for (Integer amount : transaction.getAmounts().values()) {
                        totalAmount += amount;
                    }
                }
            }
        } catch (NullPointerException e) {
            return 0;
        }

        return totalAmount;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getMode() {
        return mode;
    }

    public void setMode(Integer mode) {
        this.mode = mode;
    }

    public String getInstructions() {
        return instructions;
    }

    public void setInstructions(String instructions) {
        this.instructions = instructions;
    }

    public String getTips() {
        return tips;
    }

    public void setTips(String tips) {
        this.tips = tips;
    }

    public String getName() {
        return name;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public void calculateOrderName(String providerName, Integer provideId, String creationDate) {
        System.out.println("********************CREATION DATE=" + creationDate);

        // Mon Jan 17 01:32:09 CST 2011 E M d HH:mm:ss z y
        // String dateString=new
        // SimpleDateFormat("MMddyyyyHHmmssZ").format(creationDate);
        Date date = null;

        try {
            date = new SimpleDateFormat("EEE MMM d HH:mm:ss z y").parse(creationDate);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        String dateString = new SimpleDateFormat("MMddyyyyHHmmssZ").format(date);

        this.name = providerName + provideId + dateString;
    }

    public OrderStatusVO getOrderStatus() {
        return orderStatus;
    }

    public void setOrderStatusVO(OrderStatusVO orderStatusVO) {
        this.orderStatus = orderStatusVO;
    }

    public void setCreatedDate(Date createdDate) {
        this.createdDate = createdDate;
    }

    public Date getCreatedDate() {
        return createdDate;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setProviderId(int spId) {
        this.spId = spId;
    }

    public int getSpId() {
        return spId;
    }

    public User getOrderAssignedTo() {
        return orderAssignedTo;
    }

    public void setOrderAssignedTo(User orderAssignedTo) {
        this.orderAssignedTo = orderAssignedTo;
    }

    public List<BatchVO> getBatchList() {
        return batchList;
    }

    public void setBatchList(List<BatchVO> batchList) {
        this.batchList = batchList;
    }

    public List<String> getCommentList() {
        return commentList;
    }

    public void setCommentList(List<String> commentList) {
        this.commentList = commentList;
    }

    public User getProvider() {
        return provider;
    }

    public void setProvider(User provider) {
        this.provider = provider;
    }
}



